package cn.tedu.aop.demo;

import org.springframework.stereotype.Component;

//计算器实现类
@Component
public class CalculatorImpl implements Calculator{
    @Override
    public int add(int x, int y) {
        //        System.out.println("调用add()");
//        int a = x + y;
//        System.out.println("调用add()完毕");
//        return a;
        int result = x+y;
        System.out.println(x+"+"+y+"="+result);
        return result;
    }
    @Override
    public double add(double x, double y) {
        double result = x+y;
        System.out.println(x+"+"+y+"="+result);
        return result;
    }
    @Override
    public String add(String x, String y) {
        String result = String.valueOf(Double.parseDouble(x)+Double.parseDouble(y));
        System.out.println(x+"x"+y+"="+result);
        return result;
    }
    @Override
    public int sub(int x, int y) {
        int result =  x - y;
        System.out.println(x+"-"+y+"="+result);
        return result;
    }

    @Override
    public int mul(int x, int y) {
        int result =  x * y;
        System.out.println(x+"*"+y+"="+result);
        return result;
    }

    @Override
    public int div(int x, int y) {
        if(y==0){
            throw new RuntimeException("除数不能为0");
        }
        int result =  x / y;
        System.out.println(x+"/"+y+"="+result);
        return result;
    }
}
